package com.designpatterns.singleton.seriable;

import java.io.Serializable;

/**
 * @author Tinu 1810989@qq.com
 */
//饿汉式单例
//反序列化时导致单例破坏
public class SeriableSingleton implements Serializable {

    private static final SeriableSingleton hungrySingleton = new SeriableSingleton();

    private SeriableSingleton() {
    }

    public static SeriableSingleton getInstance() {
        return hungrySingleton;
    }

    //增加 readResolve()方法返回实例，解决单例被破坏的问题
    private  Object readResolve(){
        return hungrySingleton;
    }
}
